import { RawAssetsUrl, RawData } from "../raw-assets-info";
import { InitializeComponent } from './default-stage-components/initialize-component';
import * as Data from '../data/data';
import { Stage } from "three-lib/base/stage";
import { ILoose } from "three-lib/tool/utils";
import { AbstractAssetTaskInfo, AudioTaskInfo, CubeTextureTaskInfo, DataTaskInfo, GLTFMeshTaskInfo, TextureTaskInfo, VideoTextureTaskInfo } from "three-lib/loader/asset-task-info";
import { Camera, Light, Scene } from "three";
import { ArcRotateControls } from 'three-lib/camera/arc-rotate-controls';
import { ThreeContainer } from 'three-lib/base/three-container';


class DefaultStage extends Stage {

    protected assetTaskInfos(): ILoose<AbstractAssetTaskInfo<any, any>> {
        return Object.assign({}, [
            new GLTFMeshTaskInfo(RawAssetsUrl.changjing),

            new TextureTaskInfo(RawAssetsUrl.background),
            new TextureTaskInfo(RawAssetsUrl.ground),
            new TextureTaskInfo(RawAssetsUrl.buttonBackground),
            new TextureTaskInfo(RawAssetsUrl.buttonEditor),
            new TextureTaskInfo(RawAssetsUrl.buttonSimulation),
            new TextureTaskInfo(RawAssetsUrl.buttonClasses),
            new TextureTaskInfo('../asset/texture/icon/同步资源.png'),
            new TextureTaskInfo('../asset/texture/icon/微云课.png'),
            new TextureTaskInfo('../asset/texture/icon/我的资源.png'),
            new TextureTaskInfo('../asset/texture/icon/优质案例.png'),
            new TextureTaskInfo('../asset/texture/icon/知识学习工具.png'),
            new TextureTaskInfo('../asset/texture/icon/资源创建工具.png'),

            new CubeTextureTaskInfo(
                RawAssetsUrl.lightCubePX,
                RawAssetsUrl.lightCubePY,
                RawAssetsUrl.lightCubePZ,
                RawAssetsUrl.lightCubeNX,
                '../asset/texture/lightCube/pz.png',
                '../asset/texture/lightCube/nz.png'
            ),

            new AudioTaskInfo(RawAssetsUrl.music),

            new VideoTextureTaskInfo(RawAssetsUrl.video),
            new VideoTextureTaskInfo(RawAssetsUrl.movie),

            new DataTaskInfo(RawAssetsUrl.dataExternal as unknown as string),

        ]) as unknown as ILoose<AbstractAssetTaskInfo<any, any>>;
    }

    protected async initializeComponents(scenes: Scene[], cameras: Camera[], lights: Light[]): Promise<void> {
        InitializeComponent.initialize(this);
        this.bindData();
        Data.cameraData.reset(true);
    }

    private bindData(): void {
        Data.cameraData.onChange(() => {
            //
        });
    }

    public controls!: ArcRotateControls;

    protected initializeInput(scenes: Array<Scene>, cameras: Array<Camera>): void {

        const controls = new ArcRotateControls(cameras[0], this.canvas as unknown as HTMLDivElement);
        controls.minDistance = 2;
        controls.maxDistance = 50;
        controls.enableDamping = true;
        this.controls = controls;
    }

    public render(): void {
        super.render();
        this.controls.update(0.02)
    }

}


export { DefaultStage };